package com.rht.gulimallcoupon.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.RequestMapping;

import com.rht.gulimallcoupon.entity.CouponEntity;
import com.rht.gulimallcoupon.service.CouponService;
import com.rht.common.utils.PageUtils;
import com.rht.common.utils.R;




/**
 * 优惠券信息
 *
 * @author rht
 * @email rht@qq.com
 * @date 2024-11-07 13:55:33
 */

@RestController
@RequestMapping("gulimallcoupon/coupon")
public class CouponController {
    @Autowired
    private CouponService couponService;

    //查询所有优惠卷
    @Operation(summary = "查询所有优惠卷")
    @PostMapping("/getAllCoupon")
    public R getAllCoupon(){
        System.out.println("----------getAllCoupon--------");
            //查询所有优惠卷
        List<CouponEntity> list=couponService.list();
        return R.ok().put("list",list);
        }
    @RequestMapping("getAll")
    public R getAll(){
        System.out.println("--------getAll--------");
        List<CouponEntity> list=couponService.list();
        return R.ok().put("list",list);
    }
    @RequestMapping("getCouponById")
    public R getCouponById(){
    System.out.println("--------getCouponById----------");
    Integer id=2;
    CouponEntity coupon=couponService.getById(id);
    return R.ok().put("coupon",coupon);
    }
    /**
     * 列表
     */
    @Operation(summary ="处理查询全部,分页查询的请求")
    @RequestMapping("/list")
      public R list(@RequestParam Map<String, Object> params){
        PageUtils page = couponService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */

    @Operation(summary ="信息")
    @RequestMapping("/info/{id}")
      public R info(@PathVariable("id") Long id){
		CouponEntity coupon = couponService.getById(id);

        return R.ok().put("coupon", coupon);
    }

    /**
     * 保存
     */
    @Operation(summary ="保存")
    @RequestMapping("/save")
     public R save(@RequestBody CouponEntity coupon){
		couponService.save(coupon);

        return R.ok();
    }

    /**
     * 修改
     */
    @Operation(summary ="修改")
    @RequestMapping("/update")
     public R update(@RequestBody CouponEntity coupon){
		couponService.updateById(coupon);

        return R.ok();
    }

    /**
     * 删除
     */
    @Operation(summary ="删除")
    @RequestMapping("/delete")
      public R delete(@RequestBody Long[] ids){
		couponService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
